from selenium.webdriver.common.by import By
import time
from basepage import BasePage
from login_page import Login
from data import system_element
from first_page import FirstPage

""" 系统管理 """

class SystemPage(BasePage):

    def system_manage(self):
        self.find_element(By.CSS_SELECTOR, system_element.SYSTEMMANAGE).click()
        time.sleep(2)
        sys_manag = self.find_element(By.CSS_SELECTOR, system_element.SYS_M).text
        self.find_element(By.CSS_SELECTOR, system_element.PLATELEMENT).click()
        frame_ele = self.find_element(By.CSS_SELECTOR, system_element.PLATFRAME)
        self.swith_to_frame(frame_ele)
        time.sleep(2)
        """
            此处预留：以后要写的内容

        """
        plat_data = self.find_element(By.CSS_SELECTOR, system_element.PLATDATA).text
        self.switch_to_parentframe()
        self.find_element(By.CSS_SELECTOR,system_element.CLOSE_PLAT).click()
        print(sys_manag)
        print(plat_data)
        print("*"*20,"\n\n")

    def add_update(self):
        self.find_element(By.CSS_SELECTOR, system_element.UPDATEMANAGE).click()
        self.find_element(By.CSS_SELECTOR, system_element.ADDUPDATE).click()
        frame_ele = self.find_element(By.CSS_SELECTOR,system_element.UPDATEFRAME)
        self.swith_to_frame(frame_ele)
        time.sleep(2)
        """
            此处预留：以后要写的内容

        """
        update_data = self.find_element(By.CSS_SELECTOR, system_element.UPDATEDATA).text
        self.switch_to_parentframe()
        self.find_element(By.CSS_SELECTOR, system_element.CLOSEADDDATE)
        print(update_data)
        print("*"*20,"\n\n")

    def APPdate_history(self):
        self.find_element(By.CSS_SELECTOR,system_element.APPUPDATEHISTORY).click()
        frame_ele = self.find_element(By.CSS_SELECTOR, system_element.APPUPDATEFRAME)
        self.swith_to_frame(frame_ele)
        time.sleep(2)
        """
            此处预留：以后要写的内容

        """
        app_history_data = self.find_element(By.CSS_SELECTOR, system_element.APPUPDATEHISTORYDATA).text
        self.switch_to_parentframe()
        self.find_element(By.CSS_SELECTOR, system_element.CLOSEAPPUPDATEHISTORY).click()
        print(app_history_data)
        print("*"*20,"\n\n")

    def PCupdatehistory(self):
        self.find_element(By.CSS_SELECTOR, system_element.UPDATEMANAGE).click()
        self.find_element(By.CSS_SELECTOR, system_element.UPDATEMANAGE).click()
        self.find_element(By.CSS_SELECTOR, system_element.PCUPDATEHISTORY).click()
        time.sleep(2)
        frame_ele = self.find_element(By.CSS_SELECTOR, system_element.PCUPDATEFRAME)
        self.swith_to_frame(frame_ele)
        time.sleep(2)
        """
               此处预留：以后要写的内容

        """
        try:
            pcupdatedata = self.find_element(By.CSS_SELECTOR, system_element.PCUPDATEDATA).text
        except Exception as e:
            print(e)
        else:
            print(pcupdatedata)
        self.switch_to_parentframe()
        self.find_element(By.CSS_SELECTOR,system_element.CLOSEPCUPDATE).click()
        print("*"*20, "\n\n")

    def TVupdatehistory(self):
        self.find_element(By.CSS_SELECTOR, system_element.TVUPDATAHISTOTRY).click()
        frame_ele = self.find_element(By.CSS_SELECTOR, system_element.TVUPDATEFRAME)
        self.swith_to_frame(frame_ele)
        time.sleep(2)
        """
        此处预留：以后要写的内容
        
        """
        tv_data = self.find_element(By.CSS_SELECTOR, system_element.TVUPDATEDATA).text
        self.switch_to_parentframe()
        self.find_element(By.CSS_SELECTOR, system_element.CLOSETVUPDATA).click()
        print(tv_data)
        print("*"*20)






if __name__ == "__main__":
    from selenium import webdriver

    driver = webdriver.Firefox()
    driver.get("http://javaweb.aroundme.tv:8083/Testhuaxi/login.jsp")
    time.sleep(1)
    driver.maximize_window()
    login_ = Login(driver)
    login_.login()
    fp = FirstPage(driver)
    fp.firstpage()
    sys = SystemPage(driver)
    sys.system_manage()
    sys.add_update()
    sys.APPdate_history()
    sys.PCupdatehistory()










